package com.igoal.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.compass.annotations.SearchableId;
import org.compass.annotations.SearchableProperty;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

@Entity
@Table(name="admin_must_do_goals")
public class MustDoGoal extends BaseObject implements Audit {

	private static final long serialVersionUID = 5859867082167692996L;
	
	private Long id;
	private Goal goal;
	private Date beginDate;
	private Date endDate;
	private Date createDate;
	private Date updateDate;
	private DataStatus status;
	
	@GeneratedValue(generator = "system-foreign")
	@GenericGenerator(name = "system-foreign", 
			strategy = "foreign",
            parameters = @Parameter(name = "property", value = "goal"))
	@Id
    @SearchableId    
    @Column(name = "id", unique = true, nullable = false)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	@OneToOne(fetch = FetchType.LAZY)
	@PrimaryKeyJoinColumn
	public Goal getGoal() {
		return goal;
	}

	public void setGoal(Goal goal) {
		this.goal = goal;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="begin_date")
	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="end_date")
	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, name = "cdate")
	public Date getCreateDate() {
		return createDate;
	}

	@Enumerated(EnumType.STRING)
	@Column(nullable = false, name = "status")
	@SearchableProperty
	public DataStatus getStatus() {
		return status;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(nullable = false, name = "mdate")
	public Date getUpdateDate() {
		return updateDate;
	}

	public void setCreateDate(Date date) {
		this.createDate = date;
	}

	public void setStatus(DataStatus dataStatus) {
		this.status = dataStatus;
	}

	public void setUpdateDate(Date date) {
		this.updateDate = date;
	}

	@Override
	public boolean equals(Object o) {
		if(o != null){
			MustDoGoal that = (MustDoGoal) o;
			return goal.equals(that.goal);
		}
		return false;
	}

	@Override
	public int hashCode() {
		return goal.hashCode();
	}

	@Override
	public String toString() {
		return "Must do goal: " + goal.getTitle();
	}

}